<?php
/*
	[BuyPg] (C) 2010-2011 Buypg
	$Id: CommentAction.class.php 2011-5-5 14:26:45 wufujun $
 */

if (!defined('THINK_PATH')) {
	exit('Access Denied');
}

class CommproductAction extends BpAction{

	public function index()
	{
		global $_SGLOBAL;
		//继承初始网站系统相关信息
		$pgsys = $this->PublicPgsys;
		//网站系统相关设置在当前控制器私有设置
		$pgsys['sys_set']['set_footer_tools'] = 1; //网站页脚 ”常用工具“ 显示
		$strWhere = "";
		$strClassName = "全部分类";
		if(!empty($_GET['classid']))
		{
			$arrClass = getCategory();
			foreach($arrClass as $key=>$value)
			{
				if($value['class_id']==$_GET['classid'])
				{
					$strClassName = $value['class_name'];
				}
			}
			$strWhere = " class_id = " . $_GET['classid'];
		}
		$DbCommproduct = M("Commproduct");
		import("@.ORG.Input");//导入Input类
		import("@.ORG.Page"); //导入分页类
		$count = $DbCommproduct->where($strWhere)->count();    //计算总数
		$p = new Page ( $count, 20 );
		$arrCommproduct = $DbCommproduct->where($strWhere)->limit($p->firstRow.','.$p->listRows)->order("product_id desc")->select();
		foreach ($arrCommproduct as $key=>$value)
		{
			$arrCommproduct[$key]['product_name'] = Input::deleteHtmlTags($value['product_name']);
			$arrCommproduct[$key]['product_name2'] = msubstr($arrCommproduct[$key]['product_name'], 0, 20, 'utf-8', FALSE);
			$arrCommproduct[$key]['product_img'] = urldecode($arrCommproduct[$key]['product_img']);
			$arrCommproduct[$key]['product_link'] = urldecode($arrCommproduct[$key]['product_link']);
		}
		$p->setConfig('header','件商品');
		$p->setConfig('prev','<');
		$p->setConfig('next','>');
		$p->setConfig('first','<<');
		$p->setConfig('last','>>');
		$p->setConfig('theme', ' <span>%nowPage%/%totalPage% 页 </span> %first% %upPage% %linkPage% %downPage% %end%');
		$page = $p->show(1);
		//定义左侧分类
		$LeftCate = getLeftCategory_nbclass();
		//定义右侧专题列表
		$RightZT = getRightZT();
		//模板输出
		$this->assign('show_zhanti_menu' , 1); //左侧菜单显示专题
		$this->assign('sys_set' , $pgsys['sys_set']); //网站系统相关设置当前私有设置模板输出
		$this->assign('leftcate_commproduct' , $LeftCate);
		$this->assign('rightzt' , $RightZT);
		$this->assign('commproduct' , $arrCommproduct);
		$this->assign("classname", $strClassName);
		$this->assign('page' , $page);
		$this->display();
	}

	public function gotourl()
	{
		$DbCommproduct = M("Commproduct");
		$strCondition = "product_id=".$_GET['cpid'];
		$DbCommproduct->setInc('click_count',$strCondition,1);
		$strWhere = "product_id=".$_GET['cpid'];
		$arrCp = $DbCommproduct->where($strWhere)->find();
		$strUrl = urldecode($arrCp['product_link']);
		header("Location: $strUrl");
		exit;
	}
}

?>
